﻿using System;

namespace padmsg._api
{
    using yunio;
    internal partial class padapi
    {
        /// <summary>
        /// 发送文字消息
        /// </summary>
        public static YunioJson send_text(string uri, string token, string to_userid, string content)
        {
            uri += "/message/SendTextMessage";

            var json = new YunioJson("{'MsgItem':[]}").AddArrayItem("MsgItem", new YunioJson("{'AtWxIDList': [], 'ImageContent': '', 'MsgType': 0 }").SetText("ToUserName", to_userid).SetText("TextContent", content));
            return YunioHttp.PostJson(uri, YunioParam.New("key", token), json);
        }
        /// <summary>
        /// 发送图片消息
        /// </summary>
        public static YunioJson send_image(string uri, string token, string to_userid, string img_uri)
        {
            uri += "/message/SendImageMessage";

            var json = new YunioJson("{'MsgItem':[]}").AddArrayItem("MsgItem", new YunioJson("{'AtWxIDList': [], 'MsgType': 0, 'TextContent': ''}").SetText("ToUserName", to_userid).SetText("ImageContent", img_uri));
            return YunioHttp.PostJson(uri, YunioParam.New("key", token), json);
        }
        /// <summary>
        /// 发送语音消息
        /// </summary>
        public static YunioJson send_voice(string uri, string token, string to_userid, string  voice_data, int voice_format, int voice_second)
        {
            uri += "/message/SendVoice";

            var json = YunioJson.NewObj().SetText("ToUserName", to_userid).SetText("VoiceData", voice_data).SetNumber("VoiceFormat", voice_format).SetNumber("VoiceSecond", voice_second);
            return YunioHttp.PostJson(uri, YunioParam.New("key", token), json);
        }
        /// <summary>
        /// 发送名片消息
        /// </summary>
        public static YunioJson send_card(string uri, string token, string to_userid, string card_alis, int flag, string nickname, string cardid)
        {
            uri += "/message/ShareCardMessage";

            var json = YunioJson.NewObj().SetText("ToUserName", to_userid).SetText("CardAlias", card_alis).SetNumber("CardFlag", flag).SetText("CardNickName", nickname).SetText("CardWxId", cardid);
            return YunioHttp.PostJson(uri, YunioParam.New("key", token), json);
        }
        /// <summary>
        /// 发送emoji消息
        /// </summary>
        public static YunioJson send_emoji(string uri, string token, string to_userid, string emoji_md5, int emoji_size)
        {
            uri += "/message/SendEmojiMessage";

            var json = new YunioJson("{'EmojiList': []}").AddArrayItem("EmojiList", YunioJson.NewObj().SetText("ToUserName", to_userid).SetText("EmojiMd5", emoji_md5).SetNumber("EmojiSize", emoji_size));
            return YunioHttp.PostJson(uri, YunioParam.New("key", token), json);
        }
        /// <summary>
        /// 发送appmsg
        /// </summary>
        public static YunioJson send_appmsg(string uri, string token, string to_userid, string xml_data, int content_type)
        {
            uri += "/message/SendAppMessage";

            var json = new YunioJson("{'AppList': []}").AddArrayItem("AppList", YunioJson.NewObj().SetText("ToUserName", to_userid).SetText("ContentXML", xml_data).SetNumber("ContentType", content_type));
            return YunioHttp.PostJson(uri, YunioParam.New("key", token), json);
        }
        /// <summary>
        /// 撤回消息
        /// </summary>
        public static YunioJson revoke_send(string uri, string token, string to_userid, long msgid, long createtime, string newmsgid)
        {
            uri += "/message/RevokeMsgNew";

            var json = YunioJson.NewObj().SetText("ToUserName", to_userid).SetText("NewMsgId", newmsgid).SetNumber("ClientMsgId", msgid).SetNumber("CreateTime", createtime);
            return YunioHttp.PostJson(uri, YunioParam.New("key", token), json);
        }
        public static YunioJson send_file(string uri, string token, string to_userid, string filename, string fileuri)
        {
            uri += "/message/SendFileMessage";

            var json = YunioJson.NewObj().SetText("ToUserName", to_userid).SetText("FileName", filename).SetText("FileUrl", fileuri);
            return YunioHttp.PostJson(uri, YunioParam.New("key", token), json);
        }
    }
}
